#include <iostream>
#include <cmath>
#include <string>

bool is_prime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime_number(std::string num) {
    if (num.size() != 3) {
        std::cout << "Wrong input";
    }
    int number = std::stoi(num);
    int lower_num = number - 1;
    int upper_num = number + 1;
    while (!is_prime(lower_num) && is_prime(upper_num)) {
        lower_num--;
        upper_num++;
    }
    if (is_prime(lower_num)) {
        return lower_num;
    } else {
        return upper_num;
    }
}

int main() {

    std::string num = "";
    std::string word;
    for(int i = 0; i < 3; i++){
        std::cin >> word;
        if (word == "zero") {
            num += "0";
        } else if (word == "one") {
            num += "1";
        } else if (word == "two") {
            num += "2";
        } else if (word == "three") {
            num += "3";
        } else if (word == "four") {
            num += "4";
        } else if (word == "five") {
            num += "5";
        } else if (word == "six") {
            num += "6";
        } else if (word == "seven") {
            num += "7";
        } else if (word == "eight") {
            num += "8";
        } else if (word == "nine") {
            num += "9";
        }
    }
    int result = closest_prime_number(num);
    std::cout << result << std::endl;
    return 0;
}